package com.zhao.uitest;

import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by Zhao on 2016/2/20.
 * 自定义组件
 */
public class TitleLayout extends LinearLayout {
    private Button mBt_back;
    private Button mBt_edit;
    private TextView mTv_title;
    public TitleLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.title, this);
        mBt_back = (Button) findViewById(R.id.bt_title_back);
        mBt_edit = (Button) findViewById(R.id.bt_title_edit);
        mTv_title = (TextView) findViewById(R.id.tv_title_text);

        mTv_title.setText((getContext().getClass().getSimpleName()));
        mBt_back.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ((Activity)getContext()).finish();
            }
        });
        mBt_edit.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getContext(), "You clicked Edit button",Toast.LENGTH_SHORT).show();
            }
        });
    }
}
